package cn.bdqn.dao.question;


import cn.bdqn.pojo.question.Category;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

@Mapper
@Component
public interface CategoryDao extends BaseMapper<Category> {
//    @Select("SELECT t1.question_category_name lev1,t2.question_category_name lev2,t3.question_category_name lev3\n" +
//            "FROM question_category t1 \n" +
//            "LEFT JOIN question_category t2 on t2.question_category_parent_id = t1.question_category_id\n" +
//            "LEFT JOIN question_category t3 on t3.question_category_parent_id = t2.question_category_id\n" +
//            "WHERE t3.question_category_id = #{id}")
//    Category iGetById(Integer id);

    @Select("SELECT * \n" +
            "FROM question_category\n" +
            "WHERE question_category_parent_id = 0")
    List<Category> iSelectLev1();
    @Select("SELECT *\n" +
            "FROM question_category\n" +
            "WHERE question_category_parent_id in \n" +
            "(SELECT question_category_id FROM question_category " +
            "WHERE question_category_parent_id=0)")
    List<Category> iSelectLev2();
    @Select("SELECT *\n" +
            "FROM question_category\n" +
            "WHERE question_category_parent_id in \n" +
            "(SELECT question_category_id FROM question_category WHERE question_category_parent_id in(SELECT question_category_id FROM question_category WHERE question_category_parent_id=0))")
    List<Category> iSelectLev3();

    @Select("SELECT question_category_id FROM `question_category` \n" +
            "WHERE question_category_name = #{name}")
    int iSelectId(String name);
}
